package rrrmai.di.module;

import android.arch.lifecycle.ViewModelProviders;
import dagger.Module;
import dagger.Provides;
import rrrmai.repository.ContactRepository;
import rrrmai.repository.PostRepository;
import rrrmai.room.database.AppDataBase;
import rrrmai.service.APIService;
import rrrmai.viewmodel.ContactModelFactory;
import rrrmai.viewmodel.ContactViewModel;
import rrrmai.viewmodel.PostModelFactory;
import rrrmai.viewmodel.PostsViewModel;
import xgggh.activity.DIActivity;

/**
 * Created by summer on 2018/3/21.
 */
@Module
public class RepositoryModule {

    public RepositoryModule(){}

    @Provides
    PostsViewModel providesPostsViewModel(DIActivity activity,PostModelFactory factory){
        return ViewModelProviders.of(activity,factory).get(PostsViewModel.class);
    }

    @Provides
    PostModelFactory providesPostModelFactory(PostRepository postRepository){
        return new PostModelFactory(postRepository);
    }

    @Provides
    PostRepository providesPostRepository(APIService apiService, AppDataBase appDataBase){
        return new PostRepository(apiService,appDataBase);
    }

    //contact
    @Provides
    ContactViewModel providesContactViewModel(DIActivity activity, ContactModelFactory factory){
        return ViewModelProviders.of(activity,factory).get(ContactViewModel.class);
    }

    @Provides
    ContactModelFactory providesContactModelFactory(ContactRepository postRepository){
        return new ContactModelFactory(postRepository);
    }

    @Provides
    ContactRepository providesContactRepository(APIService apiService, AppDataBase appDataBase){
        return new ContactRepository(apiService,appDataBase);
    }





}
